﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WPFExcelReport.Controls">

    <Style TargetType="{x:Type local:Connection}">
        <Style.Resources>
            
            <local:AddDoubleConverter x:Key="AddDoubleConverter" />
            
            <!-- Arrow Grid Style -->
            <Style x:Key="ArrowGridStyle" TargetType="Grid">
                <Setter Property="Width" Value="10"/>
                <Setter Property="Height" Value="10"/>
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <TranslateTransform X="-5" Y="-5"/>
                    </Setter.Value>
                </Setter>
            </Style>
            <!-- base style for all arrow shapes -->
            <Style x:Key="ArrowSymbolBaseStyle" TargetType="Path">
                <Setter Property="Fill" Value="{Binding LineStroke}"/>
                <Setter Property="Stretch" Value="Fill"/>
            </Style>
            <!-- None (Line) -->
            <Style x:Key="None" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
                <!-- TODO: DOES NOT WORK! -->
                <Setter Property="Data" Value="M0,5 5,5 Z"/>
            </Style>

            <!-- Arrow -->
            <Style x:Key="Arrow" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
                <Setter Property="Data" Value="M0,0 8,4 0,8 Z"/>
            </Style>
            <!-- Diamond  -->
            <Style x:Key="Diamond" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
                <Setter Property="Data" Value="M-5,0 0,-5 5,0 0,5 Z"/>
            </Style>
        </Style.Resources>

        <Setter Property="LineStroke" Value="#60000000" />
        
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:Connection}">
                    <Canvas DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" >
                        <Path Name="PART_ConnectionPath"
                          StrokeThickness="{TemplateBinding LineStrokeThickness}"
                          Stroke="{TemplateBinding LineStroke}"
                          StrokeStartLineCap="Round"
                          StrokeEndLineCap="Round"
                          StrokeLineJoin="Round"
                          StrokeDashArray="{Binding StrokeDashArray}"
                          SnapsToDevicePixels="True"
                          Data="{Binding PathGeometry}">
                        </Path>
                        <Path
                          StrokeThickness="{TemplateBinding LineStrokeThickness, Converter={StaticResource AddDoubleConverter}, ConverterParameter=3}"
                          Stroke="Transparent"
                          StrokeStartLineCap="Round"
                          StrokeEndLineCap="Round"
                          StrokeLineJoin="Round"
                          SnapsToDevicePixels="True"
                          Data="{Binding PathGeometry}">
                        </Path>
                        <Grid Style="{StaticResource ArrowGridStyle}"
                              Canvas.Left="{Binding AnchorPositionSource.X}"
                              Canvas.Top="{Binding AnchorPositionSource.Y}">
                            <Path Name="PART_SourceAnchorPath"/>
                            <Grid.LayoutTransform>
                                <RotateTransform Angle="{Binding AnchorAngleSource}"/>
                            </Grid.LayoutTransform>
                        </Grid>
                        <Grid Style="{StaticResource ArrowGridStyle}"
                              Canvas.Left="{Binding AnchorPositionSink.X}"
                              Canvas.Top="{Binding AnchorPositionSink.Y}">
                            <Path Name="PART_SinkAnchorPath"/>
                            <Grid.LayoutTransform>
                                <RotateTransform Angle="{Binding AnchorAngleSink}"/>
                            </Grid.LayoutTransform>
                        </Grid>

                        <!--<Canvas.BitmapEffect>
                            <OuterGlowBitmapEffect />
                        </Canvas.BitmapEffect>-->
                        <!--<Canvas.Effect>
                            <DropShadowEffect />
                        </Canvas.Effect>-->
                    </Canvas>

                    <ControlTemplate.Triggers>
                        <DataTrigger Value="None" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
                            <Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource None}"/>
                        </DataTrigger>
                        <DataTrigger Value="Arrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
                            <Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource Arrow}"/>
                        </DataTrigger>
                        <DataTrigger Value="Diamond" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
                            <Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource Diamond}"/>
                        </DataTrigger>
                        <DataTrigger Value="None" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
                            <Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource None}"/>
                        </DataTrigger>
                        <DataTrigger Value="Arrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
                            <Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource Arrow}"/>
                        </DataTrigger>
                        <DataTrigger Value="Diamond" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
                            <Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource Diamond}"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="LineStroke" Value="Black" />
                <Setter Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>